<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>数组解构</title>
</head>
<body>
  <script>
    /**
     * 1. 解构
     * 2. 默认值/回滚值
     * 3. 交换值
    */

    // 1. 解构
    const bags = ['book', 'pencil', 'eraser'];
    const [book, , eraser] = bags;
    console.log('解构', book, eraser); // 可以用空格占据位置

    // 2. 默认值/回滚值
    const [book1, pencil1 , eraser1, knife1 = 'knife'] = bags; // 只有undefined可以重新赋值
    console.log('赋值', book1, pencil1 , eraser1, knife1);

    // 3. 交换值
    let a  = 1, b = 2, c = 3;
    [b, c, a] = [a, b, c]
    console.log(a, b, c); // 3 1 2
  </script>
</body>
</html>